package com.ssm.spring;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class BeanDefinitionTest {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        //定义 BeanDefinition
        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
        //设置 scope
        beanDefinition.setScope(BeanDefinition.SCOPE_SINGLETON);
        //设置bean类型
        beanDefinition.setBeanClass(OrderService.class);
        //设置懒加载
        beanDefinition.setLazyInit(true);
        //注册 bean
        applicationContext.registerBeanDefinition("orderService", beanDefinition);
        applicationContext.refresh();
        System.out.println(applicationContext.getBean("orderService"));
    }
}

class OrderService {

}